package com.wangsd.web.coupon.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;

/**
 * 商家券
 */
@Data
@Entity
@Table(name = "business_coupon")
@ApiModel(value = "商家券", description = "商家券")
public class BusinessCoupon {

    @ApiModelProperty(value = "id")
    /*mybatis plus 自增主键*/
    @TableId(type = IdType.AUTO)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private Date createdTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updatedTime;

    @ApiModelProperty(value = "（逻辑删除）是否已删；0，未删，1，已删")
    @TableField(fill = FieldFill.INSERT)
    private Integer deleted;

    @ApiModelProperty(value = "检索标识")
    private String code;

    @ApiModelProperty(value = "商圈id")
    private Long companyId;

    @ApiModelProperty(value = "商家券价值")
    private Integer value;

    @ApiModelProperty(value = "0未上架，1上架")
    @Column(name = "state", columnDefinition = "int(2) default 0 not null")
    private Integer state;

    @ApiModelProperty(value = "商家券使用最低限额")
    private Integer businessCouponMininumn;

    @ApiModelProperty(value = "剩余商品数量")
    @Column(name = "usable_business_coupon_count", columnDefinition = "int(20) default 0 not null")
    private Integer usableBusinessCouponCount;

    @ApiModelProperty(value = "商家券图片url")
    private String businessCouponPicUrl;

    @ApiModelProperty(value = "描述")
    @Lob
    @Column(name = "note", columnDefinition = "text")
    private String note;

    @ApiModelProperty(value = "可以获取多少积分")
    @Column(name = "points", columnDefinition = "int(11) default 0 not null")
    private Integer points;

    @ApiModelProperty(value = "商家券类型为30，固定写死")
    @Column(name = "type", columnDefinition = "int(2) default 30 not null")
    private Integer type;

    @ApiModelProperty(value = "商家券是否精品，0,非精品；1，精品")
    @Column(name = "h_type", columnDefinition = "int(2) default 0 not null")
    private Integer hType;

    @ApiModelProperty(value = "批次号")
    private String stockId;

    @ApiModelProperty(value = "商家券批次名称")
    private String stockName;

    @ApiModelProperty(value = "批次归属商户号")
    private String belongMerchant;

    @ApiModelProperty(value = "适用商品范围")
    private String goodsName;

    @ApiModelProperty(value = "批次类型  注：NORMAL：固定面额满减券批次;DISCOUNT：折扣券批次;EXCHAHGE：换购券批次 ")
    private String stockType;


    /*核销规则 --start*/


    @ApiModelProperty(value = "券可核销时间--开始时间")
    private String availableBeginTime;

    @ApiModelProperty(value = "券可核销时间--开始时间")
    private String availableEndTime;

    @ApiModelProperty(value = "券可核销时间--领取后N天内有效")
    private Integer availableDayAfterReceive;


    @ApiModelProperty(value = "固定面额满减券使用规则--优惠金额 注：stock_type为NORMAL时必填。")
    private Integer discountAmount;

    @ApiModelProperty(value = "固定面额满减券使用规则--消费门槛 注：stock_type为NORMAL,DISCOUNT,EXCHANGE时必填。")
    private Integer transactionMinimum;

    @ApiModelProperty(value = "折扣券使用规则--优惠金额 注：stock_type为DISCOUNT时必填。")
    private Integer discountPercent;

    @ApiModelProperty(value = "换购券使用规则--单品换购价 注：stock_type为DISCOUNT时必填。")
    private Integer exchangePrice;

    @ApiModelProperty(value = "核销方式 注：枚举值：OFF_LINE：线下滴码核销;MINI_PROGRAMS：线上小程序核销（需要添加小程序appid和path） ;USER_SELF：用户自主核销 ")
    private String useMethod;

    @ApiModelProperty(value = "小程序appid")
    private String miniProgramsAppid;

    @ApiModelProperty(value = "小程序path")
    private String miniProgramsPath;
    /*核销规则 --end*/

    /*发放规则 --start*/
    @ApiModelProperty(value = "批次总预算")
    private Integer maxAmount;

    @ApiModelProperty(value = "批次最大发放个数； 注：当stock_type为DISCOUNT类型时，必须填写。 ")
    private Integer maxCoupons;

    @ApiModelProperty(value = "用户最大可领个数；注：用户可领个数，每个用户最多100张券 。 ")
    private Integer maxCouponsPerUser;
    /*发放规则 --end*/

    @ApiModelProperty(value = "商户请求单号;商户创建批次凭据号（格式：商户id+日期+流水号），商户侧需保持唯一性。")
    private String outRequestNo;

    @ApiModelProperty(value = "券code模式;枚举值：" +
            "WECHATPAY_MODE：系统分配券code。" +
            "MERCHANT_API：商户发放时接口指定券code。" +
            "MERCHANT_UPLOAD：商户上传自定义code，发券时系统随机选取上传的券code。")
    private String couponCodeMode;

    @ApiModelProperty(value = "核销规则")
    @TableField(exist = false)
    @Transient
    private JSONObject couponUseRule;

    @ApiModelProperty(value = "发放规则")
    @TableField(exist = false)
    @Transient
    private JSONObject stockSendRule;

    @ApiModelProperty(value = "自定义入口")
    @TableField(exist = false)
    @Transient
    private JSONObject customEntrance;

    @ApiModelProperty(value = "样式信息")
    @TableField(exist = false)
    @Transient
    private JSONObject displayPatternInfo;
}
